package com.yociyy.common.core.execption;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 基础异常
 * 
 * @author ruoyi、YoCiyy
 */
@AllArgsConstructor
@NoArgsConstructor
public class BaseException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	/** 所属模块 */
	@Getter
	private String module;

	/** 错误码 */
	@Getter
	private String code;

	/** 错误码对应的参数 */
	@Getter
	private Object[] args;

	/** 错误消息 */
	@Getter
	private String defaultMessage;

	@Override
	public String getMessage() {
		String message = code;
//		if (!StrUtil.isEmpty(code)) {
//			MessageSource bean = SpringUtil.getBean(MessageSource.class);
//			message = bean.getMessage(code, args, LocaleContextHolder.getLocale());
//		}
//		if (message == null) {
//			message = this.defaultMessage;
//		}
		return message;
	}

}
